//index.js
//获取应用实例
import S_request from '../../utils/requestService.js';
import CONFIG from '../../config.js';
const app = getApp()
Page({
  data: {
    activityList: [],
  },
  onShareAppMessage: function(res) {
    wx.showShareMenu({
      withShareTicket: true,
      success: function() {}
    });
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    let obj = { 'pagepath': CONFIG.SHARE.path}
    S_request.index.recordShare("-1", obj);
    return {
      title: CONFIG.SHARE.title,
      path: CONFIG.SHARE.path,
      imageUrl: CONFIG.SHARE.imageUrl
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let self = this;
    let share = options.share;
    if (share == 1) {
      console.log("游戏界面转发")
    }
    S_request.mine.getActivityList((data) => {
      for (let i = 0; i < data.length; i++) {
        let list = data[i];
        list.date = this.timestampToTime(list.update_time) + " >"
        list.description = "55万现金后红包大队送给你"
      }
      // console.log("data====" + JSON.stringify(data))
      app.globalData.activityList = data;
      this.setData({
        activityList: data
      })
    });
  },

  openDetail: function(e) {
    let id = e.currentTarget.dataset.id;

    wx.navigateTo({
      url: '../htmlParse/htmlParse?id=' + id
    })
  },

  timestampToTime: function(timestamp) {
    var date = new Date(timestamp * 1000); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
    let Y = date.getFullYear() + '-';
    let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    let D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
    let h = date.getHours() + ':';
    let m = date.getMinutes() + ':';
    let s = date.getSeconds();
    return M + D;
  }

})